package de.akad.imp03.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import de.akad.imp03.client.data.Rundendaten;


public class ButtonCommand implements ClickHandler {

	private ControlCenter root;
	private Rundendaten rd;
	private int selectedItem;
	private int selectedMenu;
	
	public ButtonCommand(ControlCenter cc, Rundendaten rd, int selectedItem) {
		root = cc;
		this.rd = rd;
		this.selectedItem = selectedItem;
	}
	
	public void execute() {

		if (selectedItem >= 0) {
			
			rd.doBudgetReduzieren(selectedItem);
			root.header.budget.setText("" + rd.getBudget() + " EUR");
			switch (selectedItem) {
			case Rundendaten.FACEBOOK:
				root.nav.facebook.setEnabled(false);
				root.nav.facebookBox.setValue(true);
				break;
			case Rundendaten.STEPSTONE:
				root.nav.stepstone.setEnabled(false);
				root.nav.stepstoneBox.setValue(true);
				break;
			case Rundendaten.TWITTER:
				root.nav.twitter.setEnabled(false);
				root.nav.twitterBox.setValue(true);
				break;
			case Rundendaten.WEBSITE:
				root.nav.website.setEnabled(false);
				root.nav.websiteBox.setValue(true);
				break;
			case Rundendaten.HEADHUNTER:
				root.nav.headhunter.setEnabled(false);
				root.nav.headhunterBox.setValue(true);
				break;
			case Rundendaten.XING:
				root.nav.xing.setEnabled(false);
				root.nav.xingBox.setValue(true);
				break;
			}
		}
		selectedItem = Rundendaten.NONE;
		root.header.subtitle.setText("");
		rd.setSelectedItem(selectedItem);
		
		if (selectedMenu >= 0) {
			// TODO
		}
		EmptyContent content = new EmptyContent();
		root.content.setPanel(content.onInitialize());
	}

	@Override
	public void onClick(ClickEvent event) {
		this.execute();
		
	}

	/**
	 * @param selectedItem the selectedItem to set
	 */
	public void setSelectedItem(int selectedItem) {
		this.selectedItem = selectedItem;
	}

	/**
	 * @param selectedMenu the selectedMenu to set
	 */
	public void setSelectedMenu(int selectedMenu) {
		this.selectedMenu = selectedMenu;
	}
	
}
